Change in openvpn[master]: openvpnserv: Fix writing messages to the event log
A message that is not in the archive (sent off-list or not yet received): gerrit.1757943505000.I423c9880def0eb479abb72bef2e8034a73cf5905@...2715...
Attention is currently required from: flichtenheld, plaisthos.
Hello plaisthos, flichtenheld,
I'd like you to do a code review.
Please visit
http://gerrit.openvpn.net/c/openvpn/+/1188?usp=email
to review the following change.
Change subject: openvpnserv: Fix writing messages to the event log
......................................................................
openvpnserv: Fix writing messages to the event log
There are two problems with the current implementation:
- due to the code bug, we never display actual error message
corresponding to the Windows error code. We use FORMAT_MESSAGE_ALLOCATE_BUFFER, in which case we must pass a pointer to the LPTSTR, not the LPTSTR itself.
- The error is not displayed in the "General" tab, which is very confusing.
One needs to go to the "Details" tab to see what is wrong.
This commit solves both problems. We now display a proper error message in addition to the text provided by the service ("what went wrong"). While on it, remove trailing symbols ín a safer way.
To display the message in "General" tab, we create a registered message file (openvpnservmsg.dll), which contains message template. Note that this requires changes to the installer - we need to install the new DLL and
add a registry entry.
GitHub: https://github.com/OpenVPN/openvpn/issues/842
---
M src/openvpnserv/CMakeLists.txt
M src/openvpnserv/common.c
A src/openvpnserv/eventmsg.mc
3 files changed, 82 insertions(+), 13 deletions(-)
git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/88/1188/1
src/openvpnserv/CMakeLists.txt +34 -0
@@ -6,11 +6,14 @@ add_executable(openvpnserv) +set(MC_GEN_DIR ${CMAKE_CURRENT_BINARY_DIR}/mc) + target_include_directories(openvpnserv PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/../../ ../../include/ ../openvpn/ ../compat/ + ${MC_GEN_DIR} ) target_sources(openvpnserv PRIVATE common.c
@@ -33,3 +36,34 @@ target_compile_options(openvpnserv PRIVATE -municode) target_link_options(openvpnserv PRIVATE -municode) endif () + +# below we generate a DLL which contains an event source for event log messages from eventmsg.mc template +file(MAKE_DIRECTORY ${MC_GEN_DIR}) +set(MC_FILE ${CMAKE_CURRENT_SOURCE_DIR}/eventmsg.mc) + +find_program(MC_COMPILER NAMES mc mc.exe x86_64-w64-mingw32-windmc i686-w64-mingw32-windmc windmc) + +if (NOT MC_COMPILER) + message(FATAL_ERROR "No message compiler found.") +endif() + +add_custom_command( + OUTPUT ${MC_GEN_DIR}/eventmsg.rc ${MC_GEN_DIR}/eventmsg.h + COMMAND ${MC_COMPILER} -U -h ${MC_GEN_DIR} -r ${MC_GEN_DIR} ${MC_FILE} + DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/eventmsg.mc + VERBATIM + ) + +# generate rc file for DLL and header for the service binary +add_custom_target(msg_mc_gen ALL DEPENDS ${MC_GEN_DIR}/eventmsg.rc ${MC_GEN_DIR}/eventmsg.h) + +add_library(openvpnservmsg SHARED ${MC_GEN_DIR}/eventmsg.rc) + +if (MSVC) + set_target_properties(openvpnservmsg PROPERTIES LINK_FLAGS "/NOENTRY") +else() + target_link_options(openvpnservmsg PRIVATE "-Wl,--no-entry") +endif() + +add_dependencies(openvpnservmsg msg_mc_gen) +add_dependencies(openvpnserv msg_mc_gen)
src/openvpnserv/common.c +25 -13
@@ -22,6 +22,7 @@#include "service.h" #include "validate.h" +#include "eventmsg.h" LPCWSTR service_instance =L"" ;static wchar_t win_sys_path[MAX_PATH ];
@@ -204,24 +205,29 @@ error =GetLastError (); len =FormatMessage (FORMAT_MESSAGE_ALLOCATE_BUFFER |FORMAT_MESSAGE_FROM_SYSTEM - |FORMAT_MESSAGE_ARGUMENT_ARRAY , -NULL , error,LANG_NEUTRAL , tmp,0 ,NULL ); + |FORMAT_MESSAGE_IGNORE_INSERTS , +NULL , error,MAKELANGID (LANG_NEUTRAL ,SUBLANG_DEFAULT ), (LPTSTR )&tmp,0 ,NULL ); -if (len ==0 || (long )_countof (buf) < (long )len +14 ) +if (!len || !tmp) { - buf[0 ] =L'\0' ; - } -else - { - tmp[wcslen (tmp) -2 ] =L'\0' ;/* remove CR/LF characters */ -swprintf (buf,_countof (buf),L"%ls (0x%x)" , tmp, error); +swprintf (buf,_countof (buf),L"Unknown error (0x%lx)" , error); +if (tmp) + { +LocalFree (tmp); + } +return buf; } -if (tmp) +/* trim trailing CR / LF / spaces safely */ +while (len && (tmp[len -1 ] ==TEXT ('\r' ) || tmp[len -1 ] ==TEXT ('\n' ) || tmp[len -1 ] ==TEXT (' ' ))) { -LocalFree (tmp); + tmp[--len] =L'\0' ; } +swprintf (buf,_countof (buf),L"%ls (0x%lx)" , tmp, error); + buf[_countof (buf) -1 ] =L'\0' ; + +LocalFree (tmp);return buf; }
@@ -253,8 +259,14 @@const WCHAR *mesg[] = { msg[0 ], msg[1 ] };ReportEvent (hEventSource, - flags &MSG_FLAGS_ERROR ?EVENTLOG_ERROR_TYPE :EVENTLOG_INFORMATION_TYPE ,0 ,0 , -NULL ,2 ,0 , mesg,NULL ); + flags &MSG_FLAGS_ERROR ?EVENTLOG_ERROR_TYPE :EVENTLOG_INFORMATION_TYPE , +0 , +EVT_TEXT_2 , +NULL , +2 , +0 , + mesg, +NULL );DeregisterEventSource (hEventSource); }
src/openvpnserv/eventmsg.mc new file +23 -0
@@ -0,0 +1,23 @@ +MessageIdTypedef=DWORD + +SeverityNames=(Success=0x0:STATUS_SEVERITY_SUCCESS + Informational=0x1:STATUS_SEVERITY_INFORMATIONAL + Warning=0x2:STATUS_SEVERITY_WARNING + Error=0x3:STATUS_SEVERITY_ERROR + ) + +FacilityNames=(System=0x0:FACILITY_SYSTEM + Runtime=0x2:FACILITY_RUNTIME + Stubs=0x3:FACILITY_STUBS + Io=0x4:FACILITY_IO_ERROR_CODE +) + +LanguageNames=(English=0x409:MSG00409) + +MessageId=0x1 +Severity=Error +Facility=Runtime +SymbolicName=EVT_TEXT_2 +Language=English +%1%n%2 +.
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1188?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I423c9880def0eb479abb72bef2e8034a73cf5905
Gerrit-Change-Number: 1188
Gerrit-PatchSet: 1
Gerrit-Owner: stipa <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-MessageType: newchange
Attention is currently required from: flichtenheld, plaisthos, stipa.
selvanair has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/1188?usp=email )
Change subject: openvpnserv: Fix writing messages to the event log
......................................................................
Patch Set 1:
(2 comments)
File src/openvpnserv/common.c:
http://gerrit.openvpn.net/c/openvpn/+/1188/comment/c9d63194_9fa73d93 :
PS1, Line 209: NULL, error, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR)&tmp, 0, NULL);
Explict use of the unicode version "FormatMessageW" preferred.
http://gerrit.openvpn.net/c/openvpn/+/1188/comment/6b08b575_87668df4 :
PS1, Line 228: buf[_countof(buf) - 1] = L'\0';
Previously we removed openvp_swprintf etc. assuming this explicit null-termination is no longer required. (commit 130548fe).
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1188?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I423c9880def0eb479abb72bef2e8034a73cf5905
Gerrit-Change-Number: 1188
Gerrit-PatchSet: 1
Gerrit-Owner: stipa <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-CC: selvanair <[email protected]...>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Attention: stipa <[email protected]...>
Gerrit-Comment-Date: Mon, 15 Sep 2025 17:38:48 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Gerrit-MessageType: comment
Attention is currently required from: flichtenheld, plaisthos, stipa.
Hello flichtenheld, plaisthos,
I'd like you to reexamine a change. Please visit
http://gerrit.openvpn.net/c/openvpn/+/1188?usp=email
to look at the new patch set (#2).
Change subject: openvpnserv: Fix writing messages to the event log
......................................................................
openvpnserv: Fix writing messages to the event log
There are two problems with the current implementation:
- due to the code bug, we never display actual error message
corresponding to the Windows error code. We use FORMAT_MESSAGE_ALLOCATE_BUFFER, in which case we must pass a pointer to the LPTSTR, not the LPTSTR itself.
- The error is not displayed in the "General" tab, which is very confusing.
One needs to go to the "Details" tab to see what is wrong.
This commit solves both problems. We now display a proper error message in addition to the text provided by the service ("what went wrong"). While on it, remove trailing symbols ín a safer way.
To display the message in "General" tab, we create a registered message file (openvpnservmsg.dll), which contains message template. Note that this requires changes to the installer - we need to install the new DLL and
add a registry entry.
GitHub: https://github.com/OpenVPN/openvpn/issues/842
---
M src/openvpnserv/CMakeLists.txt
M src/openvpnserv/common.c
A src/openvpnserv/eventmsg.mc
3 files changed, 82 insertions(+), 14 deletions(-)
git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/88/1188/2
src/openvpnserv/CMakeLists.txt +34 -0
@@ -6,11 +6,14 @@ add_executable(openvpnserv) +set(MC_GEN_DIR ${CMAKE_CURRENT_BINARY_DIR}/mc) + target_include_directories(openvpnserv PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/../../ ../../include/ ../openvpn/ ../compat/ + ${MC_GEN_DIR} ) target_sources(openvpnserv PRIVATE common.c
@@ -33,3 +36,34 @@ target_compile_options(openvpnserv PRIVATE -municode) target_link_options(openvpnserv PRIVATE -municode) endif () + +# below we generate a DLL which contains an event source for event log messages from eventmsg.mc template +file(MAKE_DIRECTORY ${MC_GEN_DIR}) +set(MC_FILE ${CMAKE_CURRENT_SOURCE_DIR}/eventmsg.mc) + +find_program(MC_COMPILER NAMES mc mc.exe x86_64-w64-mingw32-windmc i686-w64-mingw32-windmc windmc) + +if (NOT MC_COMPILER) + message(FATAL_ERROR "No message compiler found.") +endif() + +add_custom_command( + OUTPUT ${MC_GEN_DIR}/eventmsg.rc ${MC_GEN_DIR}/eventmsg.h + COMMAND ${MC_COMPILER} -U -h ${MC_GEN_DIR} -r ${MC_GEN_DIR} ${MC_FILE} + DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/eventmsg.mc + VERBATIM + ) + +# generate rc file for DLL and header for the service binary +add_custom_target(msg_mc_gen ALL DEPENDS ${MC_GEN_DIR}/eventmsg.rc ${MC_GEN_DIR}/eventmsg.h) + +add_library(openvpnservmsg SHARED ${MC_GEN_DIR}/eventmsg.rc) + +if (MSVC) + set_target_properties(openvpnservmsg PROPERTIES LINK_FLAGS "/NOENTRY") +else() + target_link_options(openvpnservmsg PRIVATE "-Wl,--no-entry") +endif() + +add_dependencies(openvpnservmsg msg_mc_gen) +add_dependencies(openvpnserv msg_mc_gen)
src/openvpnserv/common.c +25 -14
@@ -22,6 +22,7 @@#include "service.h" #include "validate.h" +#include "eventmsg.h" LPCWSTR service_instance =L"" ;static wchar_t win_sys_path[MAX_PATH ];
@@ -203,25 +204,29 @@LPWSTR tmp =NULL ; error =GetLastError (); - len =FormatMessage (FORMAT_MESSAGE_ALLOCATE_BUFFER |FORMAT_MESSAGE_FROM_SYSTEM - |FORMAT_MESSAGE_ARGUMENT_ARRAY , -NULL , error,LANG_NEUTRAL , tmp,0 ,NULL ); + len =FormatMessageW (FORMAT_MESSAGE_ALLOCATE_BUFFER |FORMAT_MESSAGE_FROM_SYSTEM + |FORMAT_MESSAGE_IGNORE_INSERTS , +NULL , error,MAKELANGID (LANG_NEUTRAL ,SUBLANG_DEFAULT ), (LPTSTR )&tmp,0 ,NULL ); -if (len ==0 || (long )_countof (buf) < (long )len +14 ) +if (!len || !tmp) { - buf[0 ] =L'\0' ; - } -else - { - tmp[wcslen (tmp) -2 ] =L'\0' ;/* remove CR/LF characters */ -swprintf (buf,_countof (buf),L"%ls (0x%x)" , tmp, error); +swprintf (buf,_countof (buf),L"Unknown error (0x%lx)" , error); +if (tmp) + { +LocalFree (tmp); + } +return buf; } -if (tmp) +/* trim trailing CR / LF / spaces safely */ +while (len && (tmp[len -1 ] ==L'\r' || tmp[len -1 ] ==L'\n' || tmp[len -1 ] ==L' ' )) { -LocalFree (tmp); + tmp[--len] =L'\0' ; } +swprintf (buf,_countof (buf),L"%ls (0x%lx)" , tmp, error); + +LocalFree (tmp);return buf; }
@@ -253,8 +258,14 @@const WCHAR *mesg[] = { msg[0 ], msg[1 ] };ReportEvent (hEventSource, - flags &MSG_FLAGS_ERROR ?EVENTLOG_ERROR_TYPE :EVENTLOG_INFORMATION_TYPE ,0 ,0 , -NULL ,2 ,0 , mesg,NULL ); + flags &MSG_FLAGS_ERROR ?EVENTLOG_ERROR_TYPE :EVENTLOG_INFORMATION_TYPE , +0 , +EVT_TEXT_2 , +NULL , +2 , +0 , + mesg, +NULL );DeregisterEventSource (hEventSource); }
src/openvpnserv/eventmsg.mc new file +23 -0
@@ -0,0 +1,23 @@ +MessageIdTypedef=DWORD + +SeverityNames=(Success=0x0:STATUS_SEVERITY_SUCCESS + Informational=0x1:STATUS_SEVERITY_INFORMATIONAL + Warning=0x2:STATUS_SEVERITY_WARNING + Error=0x3:STATUS_SEVERITY_ERROR + ) + +FacilityNames=(System=0x0:FACILITY_SYSTEM + Runtime=0x2:FACILITY_RUNTIME + Stubs=0x3:FACILITY_STUBS + Io=0x4:FACILITY_IO_ERROR_CODE +) + +LanguageNames=(English=0x409:MSG00409) + +MessageId=0x1 +Severity=Error +Facility=Runtime +SymbolicName=EVT_TEXT_2 +Language=English +%1%n%2 +.
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1188?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I423c9880def0eb479abb72bef2e8034a73cf5905
Gerrit-Change-Number: 1188
Gerrit-PatchSet: 2
Gerrit-Owner: stipa <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-CC: selvanair <[email protected]...>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Attention: stipa <[email protected]...>
Gerrit-MessageType: newpatchset
Attention is currently required from: flichtenheld, plaisthos, selvanair.
stipa has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/1188?usp=email )
Change subject: openvpnserv: Fix writing messages to the event log
......................................................................
Patch Set 2:
(2 comments)
File src/openvpnserv/common.c:
http://gerrit.openvpn.net/c/openvpn/+/1188/comment/faf6c002_b6bdf61f :
PS1, Line 209: NULL, error, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR)&tmp, 0, NULL);
Quoted 1 line
Explict use of the unicode version "FormatMessageW" preferred.
Acknowledged
http://gerrit.openvpn.net/c/openvpn/+/1188/comment/33eaf24d_50732a8f :
PS1, Line 228: buf[_countof(buf) - 1] = L'\0';
Quoted 1 line
Previously we removed
openvp_swprintfetc. […]
JFTR: only MSFT version of swprintf guarantees NULL termination. Other versions won't write anything (and won't terminate) if the string doesn't fit. OTOH, we build releases with MSVC and in any case we nowadays use MSFT implementation (ucrtbase.dll) from OS.
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1188?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I423c9880def0eb479abb72bef2e8034a73cf5905
Gerrit-Change-Number: 1188
Gerrit-PatchSet: 2
Gerrit-Owner: stipa <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-CC: selvanair <[email protected]...>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Attention: selvanair <[email protected]...>
Gerrit-Comment-Date: Tue, 16 Sep 2025 07:10:24 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: selvanair <[email protected]...>
Gerrit-MessageType: comment
Attention is currently required from: flichtenheld, plaisthos, stipa.
selvanair has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/1188?usp=email )
Change subject: openvpnserv: Fix writing messages to the event log
......................................................................
Patch Set 2: Code-Review+1
(1 comment)
Patchset:
PS2:
Looks good but I have not build-tested. Can we get the gerrit checks to run?
Also, I've not been following build system changes, so not sure, but don't we still support building using autotools and mingw for Windows? Espeically cross-compiling. Could be handled in a separate patch, though.
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1188?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I423c9880def0eb479abb72bef2e8034a73cf5905
Gerrit-Change-Number: 1188
Gerrit-PatchSet: 2
Gerrit-Owner: stipa <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-Reviewer: selvanair <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Attention: stipa <[email protected]...>
Gerrit-Comment-Date: Tue, 16 Sep 2025 15:43:48 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: Yes
Gerrit-MessageType: comment
Attention is currently required from: flichtenheld, plaisthos, stipa.
selvanair has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/1188?usp=email )
Change subject: openvpnserv: Fix writing messages to the event log
......................................................................
Patch Set 2: Code-Review+2
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1188?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I423c9880def0eb479abb72bef2e8034a73cf5905
Gerrit-Change-Number: 1188
Gerrit-PatchSet: 2
Gerrit-Owner: stipa <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-Reviewer: selvanair <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Attention: stipa <[email protected]...>
Gerrit-Comment-Date: Tue, 16 Sep 2025 15:44:27 +0000
Gerrit-HasComments: No
Gerrit-Has-Labels: Yes
Gerrit-MessageType: comment
Attention is currently required from: flichtenheld, plaisthos, stipa.
selvanair has removed a vote from this change. ( http://gerrit.openvpn.net/c/openvpn/+/1188?usp=email )
Change subject: openvpnserv: Fix writing messages to the event log
......................................................................
Removed Code-Review+2 by selvanair <[email protected]...>
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1188?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I423c9880def0eb479abb72bef2e8034a73cf5905
Gerrit-Change-Number: 1188
Gerrit-PatchSet: 2
Gerrit-Owner: stipa <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-Reviewer: selvanair <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Attention: stipa <[email protected]...>
Gerrit-MessageType: deleteVote
Attention is currently required from: flichtenheld, plaisthos, stipa.
cron2 has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/1188?usp=email )
Change subject: openvpnserv: Fix writing messages to the event log
......................................................................
Patch Set 2:
(1 comment)
Patchset:
PS2:
@[email protected]... - if you're fine with the patch otherwise, feel free to +2 it. I'll volunteer to take care of the autconf bits (and send in a followup patch).
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1188?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I423c9880def0eb479abb72bef2e8034a73cf5905
Gerrit-Change-Number: 1188
Gerrit-PatchSet: 2
Gerrit-Owner: stipa <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-Reviewer: selvanair <[email protected]...>
Gerrit-CC: cron2 <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Attention: stipa <[email protected]...>
Gerrit-Comment-Date: Tue, 16 Sep 2025 16:51:25 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Gerrit-MessageType: comment
Attention is currently required from: cron2, flichtenheld, plaisthos, stipa.
selvanair has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/1188?usp=email )
Change subject: openvpnserv: Fix writing messages to the event log
......................................................................
Patch Set 2:
(1 comment)
Patchset:
PS2:
Quoted 1 line
@[email protected]... - if you're fine with the patch otherwise, feel free to +2 it. […]
Trying to find some time to build test it. autotools thing can wait (or be deprecated) as cmake build using mingw is probably supported.
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1188?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I423c9880def0eb479abb72bef2e8034a73cf5905
Gerrit-Change-Number: 1188
Gerrit-PatchSet: 2
Gerrit-Owner: stipa <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-Reviewer: selvanair <[email protected]...>
Gerrit-CC: cron2 <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: cron2 <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Attention: stipa <[email protected]...>
Gerrit-Comment-Date: Tue, 16 Sep 2025 17:39:03 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: cron2 <[email protected]...>
Gerrit-MessageType: comment
Attention is currently required from: cron2, flichtenheld, plaisthos, stipa.
selvanair has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/1188?usp=email )
Change subject: openvpnserv: Fix writing messages to the event log
......................................................................
Patch Set 2:
(1 comment)
Patchset:
PS2:
Building with cmake and mingw using mingw-x64 preset works, but openvpnservmsg.dll not generated. eventmsg.h and rc do get made without error. If there is an MSVC build artifact somewhere, I can test it.
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1188?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I423c9880def0eb479abb72bef2e8034a73cf5905
Gerrit-Change-Number: 1188
Gerrit-PatchSet: 2
Gerrit-Owner: stipa <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-Reviewer: selvanair <[email protected]...>
Gerrit-CC: cron2 <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: cron2 <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Attention: stipa <[email protected]...>
Gerrit-Comment-Date: Tue, 16 Sep 2025 17:42:20 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Gerrit-MessageType: comment
Attention is currently required from: cron2, flichtenheld, plaisthos, stipa.
selvanair has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/1188?usp=email )
Change subject: openvpnserv: Fix writing messages to the event log
......................................................................
Patch Set 2: Code-Review+2
(1 comment)
Patchset:
PS2:
cmake-MSVC build is good and the dll works as expected. Fixing cmake-mingw build may be handled in a separate patch.
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1188?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I423c9880def0eb479abb72bef2e8034a73cf5905
Gerrit-Change-Number: 1188
Gerrit-PatchSet: 2
Gerrit-Owner: stipa <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-Reviewer: selvanair <[email protected]...>
Gerrit-CC: cron2 <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: cron2 <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Attention: stipa <[email protected]...>
Gerrit-Comment-Date: Tue, 16 Sep 2025 21:27:38 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: Yes
Gerrit-MessageType: comment
Attention is currently required from: cron2, flichtenheld, plaisthos.
stipa has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/1188?usp=email )
Change subject: openvpnserv: Fix writing messages to the event log
......................................................................
Patch Set 2:
(1 comment)
Patchset:
PS2:
Quoted 1 line
Building with cmake and mingw using mingw-x64 preset works, but openvpnservmsg.dll not generated. […]
I haven't tried mingw myself but GHA log says:
[261/267] Linking RC shared library src/openvpnserv/Debug/libopenvpnservmsg.dll
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1188?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I423c9880def0eb479abb72bef2e8034a73cf5905
Gerrit-Change-Number: 1188
Gerrit-PatchSet: 2
Gerrit-Owner: stipa <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-Reviewer: selvanair <[email protected]...>
Gerrit-CC: cron2 <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: cron2 <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Comment-Date: Wed, 17 Sep 2025 07:12:49 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: selvanair <[email protected]...>
Gerrit-MessageType: comment
PATCH v2 1/1 openvpnserv: Fix writing messages to the event log
In reply to a message not in the archiveFrom: Lev Stipakov <[email protected]...>
There are two problems with the current implementation:
- due to the code bug, we never display actual error message
corresponding to the Windows error code. We use FORMAT_MESSAGE_ALLOCATE_BUFFER, in which case we must pass a pointer to the LPTSTR, not the LPTSTR itself.
- The error is not displayed in the "General" tab, which is very confusing.
One needs to go to the "Details" tab to see what is wrong.
This commit solves both problems. We now display a proper error message in addition to the text provided by the service ("what went wrong"). While on it, remove trailing symbols ín a safer way.
To display the message in "General" tab, we create a registered message file (openvpnservmsg.dll), which contains message template. Note that this requires changes to the installer - we need to install the new DLL and
add a registry entry.
GitHub: https://github.com/OpenVPN/openvpn/issues/842
---
This change was reviewed on Gerrit and approved by at least one developer. I request to merge it to master.
Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1188
This mail reflects revision 2 of this Change.
Acked-by according to Gerrit (reflected above):
Selva Nair <[email protected]...>
src/openvpnserv/CMakeLists.txt +34 -0
@@ -6,11 +6,14 @@ add_executable(openvpnserv) +set(MC_GEN_DIR ${CMAKE_CURRENT_BINARY_DIR}/mc) + target_include_directories(openvpnserv PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/../../ ../../include/ ../openvpn/ ../compat/ + ${MC_GEN_DIR} ) target_sources(openvpnserv PRIVATE common.c
@@ -33,3 +36,34 @@ target_compile_options(openvpnserv PRIVATE -municode) target_link_options(openvpnserv PRIVATE -municode) endif () + +# below we generate a DLL which contains an event source for event log messages from eventmsg.mc template +file(MAKE_DIRECTORY ${MC_GEN_DIR}) +set(MC_FILE ${CMAKE_CURRENT_SOURCE_DIR}/eventmsg.mc) + +find_program(MC_COMPILER NAMES mc mc.exe x86_64-w64-mingw32-windmc i686-w64-mingw32-windmc windmc) + +if (NOT MC_COMPILER) + message(FATAL_ERROR "No message compiler found.") +endif() + +add_custom_command( + OUTPUT ${MC_GEN_DIR}/eventmsg.rc ${MC_GEN_DIR}/eventmsg.h + COMMAND ${MC_COMPILER} -U -h ${MC_GEN_DIR} -r ${MC_GEN_DIR} ${MC_FILE} + DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/eventmsg.mc + VERBATIM + ) + +# generate rc file for DLL and header for the service binary +add_custom_target(msg_mc_gen ALL DEPENDS ${MC_GEN_DIR}/eventmsg.rc ${MC_GEN_DIR}/eventmsg.h) + +add_library(openvpnservmsg SHARED ${MC_GEN_DIR}/eventmsg.rc) + +if (MSVC) + set_target_properties(openvpnservmsg PROPERTIES LINK_FLAGS "/NOENTRY") +else() + target_link_options(openvpnservmsg PRIVATE "-Wl,--no-entry") +endif() + +add_dependencies(openvpnservmsg msg_mc_gen) +add_dependencies(openvpnserv msg_mc_gen)
src/openvpnserv/common.c +25 -14
@@ -22,6 +22,7 @@#include "service.h" #include "validate.h" +#include "eventmsg.h" LPCWSTR service_instance =L"" ;static wchar_t win_sys_path[MAX_PATH ];
@@ -203,25 +204,29 @@LPWSTR tmp =NULL ; error =GetLastError (); - len =FormatMessage (FORMAT_MESSAGE_ALLOCATE_BUFFER |FORMAT_MESSAGE_FROM_SYSTEM - |FORMAT_MESSAGE_ARGUMENT_ARRAY , -NULL , error,LANG_NEUTRAL , tmp,0 ,NULL ); + len =FormatMessageW (FORMAT_MESSAGE_ALLOCATE_BUFFER |FORMAT_MESSAGE_FROM_SYSTEM + |FORMAT_MESSAGE_IGNORE_INSERTS , +NULL , error,MAKELANGID (LANG_NEUTRAL ,SUBLANG_DEFAULT ), (LPTSTR )&tmp,0 ,NULL ); -if (len ==0 || (long )_countof (buf) < (long )len +14 ) +if (!len || !tmp) { - buf[0 ] =L'\0' ; - } -else - { - tmp[wcslen (tmp) -2 ] =L'\0' ;/* remove CR/LF characters */ -swprintf (buf,_countof (buf),L"%ls (0x%x)" , tmp, error); +swprintf (buf,_countof (buf),L"Unknown error (0x%lx)" , error); +if (tmp) + { +LocalFree (tmp); + } +return buf; } -if (tmp) +/* trim trailing CR / LF / spaces safely */ +while (len && (tmp[len -1 ] ==L'\r' || tmp[len -1 ] ==L'\n' || tmp[len -1 ] ==L' ' )) { -LocalFree (tmp); + tmp[--len] =L'\0' ; } +swprintf (buf,_countof (buf),L"%ls (0x%lx)" , tmp, error); + +LocalFree (tmp);return buf; }
@@ -253,8 +258,14 @@const WCHAR *mesg[] = { msg[0 ], msg[1 ] };ReportEvent (hEventSource, - flags &MSG_FLAGS_ERROR ?EVENTLOG_ERROR_TYPE :EVENTLOG_INFORMATION_TYPE ,0 ,0 , -NULL ,2 ,0 , mesg,NULL ); + flags &MSG_FLAGS_ERROR ?EVENTLOG_ERROR_TYPE :EVENTLOG_INFORMATION_TYPE , +0 , +EVT_TEXT_2 , +NULL , +2 , +0 , + mesg, +NULL );DeregisterEventSource (hEventSource); }
src/openvpnserv/eventmsg.mc new file +23 -0
@@ -0,0 +1,23 @@ +MessageIdTypedef=DWORD + +SeverityNames=(Success=0x0:STATUS_SEVERITY_SUCCESS + Informational=0x1:STATUS_SEVERITY_INFORMATIONAL + Warning=0x2:STATUS_SEVERITY_WARNING + Error=0x3:STATUS_SEVERITY_ERROR + ) + +FacilityNames=(System=0x0:FACILITY_SYSTEM + Runtime=0x2:FACILITY_RUNTIME + Stubs=0x3:FACILITY_STUBS + Io=0x4:FACILITY_IO_ERROR_CODE +) + +LanguageNames=(English=0x409:MSG00409) + +MessageId=0x1 +Severity=Error +Facility=Runtime +SymbolicName=EVT_TEXT_2 +Language=English +%1%n%2 +.
[Openvpn-devel] [PATCH applied] Re: openvpnserv: Fix writing messages to the event log
So this has a bit of a complicated journey - the initial patch was gerrit 1183 for 2.6, which had v1..v3, and then this one for master, which only got up to v2 but is now the same code change, essentially.
I have tested a 2.6 installer with this, and it makes really nice log entries in the event log - so definitely a MUST HAVE.
HEADS UP: when building installers with "autoconf" on mingw, this will not currently produce the necessary .dll to proceed. I'll send a patch to add this. The official way releases are built is "cmake with msvc" or "cmake with mingw", and both produce the new .dll - and for "just build a test openvpn.exe with configure/mingw" this is not critical (which is what I usually do).
Your patch has been applied to the master branch.
commit 06919a60ae61d6d88546b23b52092f742599a8ae
Author: Lev Stipakov Date: Wed Sep 17 11:05:48 2025 +0200
openvpnserv: Fix writing messages to the event log
Signed-off-by: Lev Stipakov <[email protected]...>
Acked-by: Selva Nair <[email protected]...>
Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1188
Message-Id: <[email protected]...>
URL: https://sourceforge.net/p/openvpn/mailman/message/59234559/
Signed-off-by: Gert Doering <[email protected]...>--
kind regards,
Gert Doering
Attention is currently required from: cron2, plaisthos, stipa.
flichtenheld has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/1188?usp=email )
Change subject: openvpnserv: Fix writing messages to the event log
......................................................................
Patch Set 2:
(1 comment)
Patchset:
PS2:
Quoted 1 line
I haven't tried mingw myself but GHA log says: […]
FWIW, buildbot also has a mingw build and it shows it generates the file. @[email protected]... do you have a build log from your cmake+mingw build?
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1188?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I423c9880def0eb479abb72bef2e8034a73cf5905
Gerrit-Change-Number: 1188
Gerrit-PatchSet: 2
Gerrit-Owner: stipa <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-Reviewer: selvanair <[email protected]...>
Gerrit-CC: cron2 <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: cron2 <[email protected]...>
Gerrit-Attention: stipa <[email protected]...>
Gerrit-Comment-Date: Wed, 17 Sep 2025 10:40:34 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: selvanair <[email protected]...>
Comment-In-Reply-To: stipa <[email protected]...>
Gerrit-MessageType: comment
cron2 has uploaded a new patch set (#3) to the change originally created by stipa. ( http://gerrit.openvpn.net/c/openvpn/+/1188?usp=email )
The following approvals got outdated and were removed:
Code-Review+2 by selvanair
Change subject: openvpnserv: Fix writing messages to the event log
......................................................................
openvpnserv: Fix writing messages to the event log
There are two problems with the current implementation:
- due to the code bug, we never display actual error message
corresponding to the Windows error code. We use FORMAT_MESSAGE_ALLOCATE_BUFFER, in which case we must pass a pointer to the LPTSTR, not the LPTSTR itself.
- The error is not displayed in the "General" tab, which is very confusing.
One needs to go to the "Details" tab to see what is wrong.
This commit solves both problems. We now display a proper error message in addition to the text provided by the service ("what went wrong"). While on it, remove trailing symbols ín a safer way.
To display the message in "General" tab, we create a registered message file (openvpnservmsg.dll), which contains message template. Note that this requires changes to the installer - we need to install the new DLL and
add a registry entry.
GitHub: https://github.com/OpenVPN/openvpn/issues/842
Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1188
Message-Id: <[email protected]...>
URL: https://sourceforge.net/p/openvpn/mailman/message/59234559/
---
M src/openvpnserv/CMakeLists.txt
M src/openvpnserv/common.c
A src/openvpnserv/eventmsg.mc
3 files changed, 82 insertions(+), 14 deletions(-)
git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/88/1188/3
src/openvpnserv/CMakeLists.txt +34 -0
@@ -6,11 +6,14 @@ add_executable(openvpnserv) +set(MC_GEN_DIR ${CMAKE_CURRENT_BINARY_DIR}/mc) + target_include_directories(openvpnserv PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/../../ ../../include/ ../openvpn/ ../compat/ + ${MC_GEN_DIR} ) target_sources(openvpnserv PRIVATE common.c
@@ -33,3 +36,34 @@ target_compile_options(openvpnserv PRIVATE -municode) target_link_options(openvpnserv PRIVATE -municode) endif () + +# below we generate a DLL which contains an event source for event log messages from eventmsg.mc template +file(MAKE_DIRECTORY ${MC_GEN_DIR}) +set(MC_FILE ${CMAKE_CURRENT_SOURCE_DIR}/eventmsg.mc) + +find_program(MC_COMPILER NAMES mc mc.exe x86_64-w64-mingw32-windmc i686-w64-mingw32-windmc windmc) + +if (NOT MC_COMPILER) + message(FATAL_ERROR "No message compiler found.") +endif() + +add_custom_command( + OUTPUT ${MC_GEN_DIR}/eventmsg.rc ${MC_GEN_DIR}/eventmsg.h + COMMAND ${MC_COMPILER} -U -h ${MC_GEN_DIR} -r ${MC_GEN_DIR} ${MC_FILE} + DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/eventmsg.mc + VERBATIM + ) + +# generate rc file for DLL and header for the service binary +add_custom_target(msg_mc_gen ALL DEPENDS ${MC_GEN_DIR}/eventmsg.rc ${MC_GEN_DIR}/eventmsg.h) + +add_library(openvpnservmsg SHARED ${MC_GEN_DIR}/eventmsg.rc) + +if (MSVC) + set_target_properties(openvpnservmsg PROPERTIES LINK_FLAGS "/NOENTRY") +else() + target_link_options(openvpnservmsg PRIVATE "-Wl,--no-entry") +endif() + +add_dependencies(openvpnservmsg msg_mc_gen) +add_dependencies(openvpnserv msg_mc_gen)
src/openvpnserv/common.c +25 -14
@@ -22,6 +22,7 @@#include "service.h" #include "validate.h" +#include "eventmsg.h" LPCWSTR service_instance =L"" ;static wchar_t win_sys_path[MAX_PATH ];
@@ -203,25 +204,29 @@LPWSTR tmp =NULL ; error =GetLastError (); - len =FormatMessage (FORMAT_MESSAGE_ALLOCATE_BUFFER |FORMAT_MESSAGE_FROM_SYSTEM - |FORMAT_MESSAGE_ARGUMENT_ARRAY , -NULL , error,LANG_NEUTRAL , tmp,0 ,NULL ); + len =FormatMessageW (FORMAT_MESSAGE_ALLOCATE_BUFFER |FORMAT_MESSAGE_FROM_SYSTEM + |FORMAT_MESSAGE_IGNORE_INSERTS , +NULL , error,MAKELANGID (LANG_NEUTRAL ,SUBLANG_DEFAULT ), (LPTSTR )&tmp,0 ,NULL ); -if (len ==0 || (long )_countof (buf) < (long )len +14 ) +if (!len || !tmp) { - buf[0 ] =L'\0' ; - } -else - { - tmp[wcslen (tmp) -2 ] =L'\0' ;/* remove CR/LF characters */ -swprintf (buf,_countof (buf),L"%ls (0x%x)" , tmp, error); +swprintf (buf,_countof (buf),L"Unknown error (0x%lx)" , error); +if (tmp) + { +LocalFree (tmp); + } +return buf; } -if (tmp) +/* trim trailing CR / LF / spaces safely */ +while (len && (tmp[len -1 ] ==L'\r' || tmp[len -1 ] ==L'\n' || tmp[len -1 ] ==L' ' )) { -LocalFree (tmp); + tmp[--len] =L'\0' ; } +swprintf (buf,_countof (buf),L"%ls (0x%lx)" , tmp, error); + +LocalFree (tmp);return buf; }
@@ -253,8 +258,14 @@const WCHAR *mesg[] = { msg[0 ], msg[1 ] };ReportEvent (hEventSource, - flags &MSG_FLAGS_ERROR ?EVENTLOG_ERROR_TYPE :EVENTLOG_INFORMATION_TYPE ,0 ,0 , -NULL ,2 ,0 , mesg,NULL ); + flags &MSG_FLAGS_ERROR ?EVENTLOG_ERROR_TYPE :EVENTLOG_INFORMATION_TYPE , +0 , +EVT_TEXT_2 , +NULL , +2 , +0 , + mesg, +NULL );DeregisterEventSource (hEventSource); }
src/openvpnserv/eventmsg.mc new file +23 -0
@@ -0,0 +1,23 @@ +MessageIdTypedef=DWORD + +SeverityNames=(Success=0x0:STATUS_SEVERITY_SUCCESS + Informational=0x1:STATUS_SEVERITY_INFORMATIONAL + Warning=0x2:STATUS_SEVERITY_WARNING + Error=0x3:STATUS_SEVERITY_ERROR + ) + +FacilityNames=(System=0x0:FACILITY_SYSTEM + Runtime=0x2:FACILITY_RUNTIME + Stubs=0x3:FACILITY_STUBS + Io=0x4:FACILITY_IO_ERROR_CODE +) + +LanguageNames=(English=0x409:MSG00409) + +MessageId=0x1 +Severity=Error +Facility=Runtime +SymbolicName=EVT_TEXT_2 +Language=English +%1%n%2 +.
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1188?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I423c9880def0eb479abb72bef2e8034a73cf5905
Gerrit-Change-Number: 1188
Gerrit-PatchSet: 3
Gerrit-Owner: stipa <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-Reviewer: selvanair <[email protected]...>
Gerrit-CC: cron2 <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-MessageType: newpatchset
cron2 has submitted this change. ( http://gerrit.openvpn.net/c/openvpn/+/1188?usp=email )
Change subject: openvpnserv: Fix writing messages to the event log
......................................................................
openvpnserv: Fix writing messages to the event log
There are two problems with the current implementation:
- due to the code bug, we never display actual error message
corresponding to the Windows error code. We use FORMAT_MESSAGE_ALLOCATE_BUFFER, in which case we must pass a pointer to the LPTSTR, not the LPTSTR itself.
- The error is not displayed in the "General" tab, which is very confusing.
One needs to go to the "Details" tab to see what is wrong.
This commit solves both problems. We now display a proper error message in addition to the text provided by the service ("what went wrong"). While on it, remove trailing symbols ín a safer way.
To display the message in "General" tab, we create a registered message file (openvpnservmsg.dll), which contains message template. Note that this requires changes to the installer - we need to install the new DLL and
add a registry entry.
GitHub: https://github.com/OpenVPN/openvpn/issues/842
Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1188
Message-Id: <[email protected]...>
URL: https://sourceforge.net/p/openvpn/mailman/message/59234559/
---
M src/openvpnserv/CMakeLists.txt
M src/openvpnserv/common.c
A src/openvpnserv/eventmsg.mc
3 files changed, 82 insertions(+), 14 deletions(-)
src/openvpnserv/CMakeLists.txt +34 -0
@@ -6,11 +6,14 @@ add_executable(openvpnserv) +set(MC_GEN_DIR ${CMAKE_CURRENT_BINARY_DIR}/mc) + target_include_directories(openvpnserv PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/../../ ../../include/ ../openvpn/ ../compat/ + ${MC_GEN_DIR} ) target_sources(openvpnserv PRIVATE common.c
@@ -33,3 +36,34 @@ target_compile_options(openvpnserv PRIVATE -municode) target_link_options(openvpnserv PRIVATE -municode) endif () + +# below we generate a DLL which contains an event source for event log messages from eventmsg.mc template +file(MAKE_DIRECTORY ${MC_GEN_DIR}) +set(MC_FILE ${CMAKE_CURRENT_SOURCE_DIR}/eventmsg.mc) + +find_program(MC_COMPILER NAMES mc mc.exe x86_64-w64-mingw32-windmc i686-w64-mingw32-windmc windmc) + +if (NOT MC_COMPILER) + message(FATAL_ERROR "No message compiler found.") +endif() + +add_custom_command( + OUTPUT ${MC_GEN_DIR}/eventmsg.rc ${MC_GEN_DIR}/eventmsg.h + COMMAND ${MC_COMPILER} -U -h ${MC_GEN_DIR} -r ${MC_GEN_DIR} ${MC_FILE} + DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/eventmsg.mc + VERBATIM + ) + +# generate rc file for DLL and header for the service binary +add_custom_target(msg_mc_gen ALL DEPENDS ${MC_GEN_DIR}/eventmsg.rc ${MC_GEN_DIR}/eventmsg.h) + +add_library(openvpnservmsg SHARED ${MC_GEN_DIR}/eventmsg.rc) + +if (MSVC) + set_target_properties(openvpnservmsg PROPERTIES LINK_FLAGS "/NOENTRY") +else() + target_link_options(openvpnservmsg PRIVATE "-Wl,--no-entry") +endif() + +add_dependencies(openvpnservmsg msg_mc_gen) +add_dependencies(openvpnserv msg_mc_gen)
src/openvpnserv/common.c +25 -14
@@ -22,6 +22,7 @@#include "service.h" #include "validate.h" +#include "eventmsg.h" LPCWSTR service_instance =L"" ;static wchar_t win_sys_path[MAX_PATH ];
@@ -203,25 +204,29 @@LPWSTR tmp =NULL ; error =GetLastError (); - len =FormatMessage (FORMAT_MESSAGE_ALLOCATE_BUFFER |FORMAT_MESSAGE_FROM_SYSTEM - |FORMAT_MESSAGE_ARGUMENT_ARRAY , -NULL , error,LANG_NEUTRAL , tmp,0 ,NULL ); + len =FormatMessageW (FORMAT_MESSAGE_ALLOCATE_BUFFER |FORMAT_MESSAGE_FROM_SYSTEM + |FORMAT_MESSAGE_IGNORE_INSERTS , +NULL , error,MAKELANGID (LANG_NEUTRAL ,SUBLANG_DEFAULT ), (LPTSTR )&tmp,0 ,NULL ); -if (len ==0 || (long )_countof (buf) < (long )len +14 ) +if (!len || !tmp) { - buf[0 ] =L'\0' ; - } -else - { - tmp[wcslen (tmp) -2 ] =L'\0' ;/* remove CR/LF characters */ -swprintf (buf,_countof (buf),L"%ls (0x%x)" , tmp, error); +swprintf (buf,_countof (buf),L"Unknown error (0x%lx)" , error); +if (tmp) + { +LocalFree (tmp); + } +return buf; } -if (tmp) +/* trim trailing CR / LF / spaces safely */ +while (len && (tmp[len -1 ] ==L'\r' || tmp[len -1 ] ==L'\n' || tmp[len -1 ] ==L' ' )) { -LocalFree (tmp); + tmp[--len] =L'\0' ; } +swprintf (buf,_countof (buf),L"%ls (0x%lx)" , tmp, error); + +LocalFree (tmp);return buf; }
@@ -253,8 +258,14 @@const WCHAR *mesg[] = { msg[0 ], msg[1 ] };ReportEvent (hEventSource, - flags &MSG_FLAGS_ERROR ?EVENTLOG_ERROR_TYPE :EVENTLOG_INFORMATION_TYPE ,0 ,0 , -NULL ,2 ,0 , mesg,NULL ); + flags &MSG_FLAGS_ERROR ?EVENTLOG_ERROR_TYPE :EVENTLOG_INFORMATION_TYPE , +0 , +EVT_TEXT_2 , +NULL , +2 , +0 , + mesg, +NULL );DeregisterEventSource (hEventSource); }
src/openvpnserv/eventmsg.mc new file +23 -0
@@ -0,0 +1,23 @@ +MessageIdTypedef=DWORD + +SeverityNames=(Success=0x0:STATUS_SEVERITY_SUCCESS + Informational=0x1:STATUS_SEVERITY_INFORMATIONAL + Warning=0x2:STATUS_SEVERITY_WARNING + Error=0x3:STATUS_SEVERITY_ERROR + ) + +FacilityNames=(System=0x0:FACILITY_SYSTEM + Runtime=0x2:FACILITY_RUNTIME + Stubs=0x3:FACILITY_STUBS + Io=0x4:FACILITY_IO_ERROR_CODE +) + +LanguageNames=(English=0x409:MSG00409) + +MessageId=0x1 +Severity=Error +Facility=Runtime +SymbolicName=EVT_TEXT_2 +Language=English +%1%n%2 +.
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1188?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I423c9880def0eb479abb72bef2e8034a73cf5905
Gerrit-Change-Number: 1188
Gerrit-PatchSet: 3
Gerrit-Owner: stipa <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-Reviewer: selvanair <[email protected]...>
Gerrit-CC: cron2 <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-MessageType: merged
selvanair has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/1188?usp=email )
Change subject: openvpnserv: Fix writing messages to the event log
......................................................................
Patch Set 3:
(1 comment)
Patchset:
PS2:
Quoted 1 line
FWIW, buildbot also has a mingw build and it shows it generates the file. @[email protected]... […]
If that is so, all is good. Does the log just show building, or is the dll really generated as well? Also, is there a way to see buildbot logs -- for me the link always times out trying to connect to some AWS site.
Further, is --no-entry really a valid linker option? Googling brings it up but that could be an "AI hallucination" based on MSVC's /NOENTRY. Anyway, I cant get that option to work. A way to make DLLs with no entry point using gnu linker is probably to pass -nostartfiles option to gcc.
That said, I get no build errors -- just no dll to be found anyhere, nor the command building it is in the verbose logs.(https://gist.github.com/selvanair/7145365eab2b38c2c961646efca692ea).
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1188?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I423c9880def0eb479abb72bef2e8034a73cf5905
Gerrit-Change-Number: 1188
Gerrit-PatchSet: 3
Gerrit-Owner: stipa <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-Reviewer: selvanair <[email protected]...>
Gerrit-CC: cron2 <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Comment-Date: Wed, 17 Sep 2025 23:39:32 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: flichtenheld <[email protected]...>
Comment-In-Reply-To: selvanair <[email protected]...>
Comment-In-Reply-To: stipa <[email protected]...>
Gerrit-MessageType: comment
cron2 has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/1188?usp=email )
Change subject: openvpnserv: Fix writing messages to the event log
......................................................................
Patch Set 3:
(1 comment)
Patchset:
PS2:
Quoted 1 line
If that is so, all is good. […]
Line #336 has something, the target binary is "libopenvpnservmsg.dll"
``` [336/348] : && cd /home/selva/openvpn/out/build/mingw/x64/src/openvpnserv && /snap/bin/pwsh -noprofile -executionpolicy Bypass -file /home/selva/vcpkg/scripts/buildsystems/msbuild/applocal.ps1 -targetBinary /home/selva/openvpn/out/build/mingw/x64/src/openvpnserv/Release/libopenvpnservmsg.dll -installedDir /home/selva/openvpn/out/build/mingw/x64/vcpkg_installed/x64-mingw-ovpn/bin -OutVariable out ```
I won't claim to understand what it's doing, though...
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1188?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I423c9880def0eb479abb72bef2e8034a73cf5905
Gerrit-Change-Number: 1188
Gerrit-PatchSet: 3
Gerrit-Owner: stipa <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-Reviewer: selvanair <[email protected]...>
Gerrit-CC: cron2 <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Comment-Date: Thu, 18 Sep 2025 06:29:44 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: flichtenheld <[email protected]...>
Comment-In-Reply-To: selvanair <[email protected]...>
Comment-In-Reply-To: stipa <[email protected]...>
Gerrit-MessageType: comment
selvanair has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/1188?usp=email )
Change subject: openvpnserv: Fix writing messages to the event log
......................................................................
Patch Set 3:
(1 comment)
Patchset:
PS2:
Quoted 1 line
Line #336 has something, the target binary is "libopenvpnservmsg.dll" […]
That's the POST_BUILD task running a powershell script. Apparently that script appears to just exit if neither source binary nor target binary is found. There is no linking steps for this dll in the verbose logs.
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1188?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I423c9880def0eb479abb72bef2e8034a73cf5905
Gerrit-Change-Number: 1188
Gerrit-PatchSet: 3
Gerrit-Owner: stipa <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-Reviewer: selvanair <[email protected]...>
Gerrit-CC: cron2 <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Comment-Date: Thu, 18 Sep 2025 15:17:20 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: cron2 <[email protected]...>
Comment-In-Reply-To: flichtenheld <[email protected]...>
Comment-In-Reply-To: selvanair <[email protected]...>
Comment-In-Reply-To: stipa <[email protected]...>
Gerrit-MessageType: comment
cron2 has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/1188?usp=email )
Change subject: openvpnserv: Fix writing messages to the event log
......................................................................
Patch Set 3:
(1 comment)
Patchset:
PS2:
Quoted 1 line
That's the
POST_BUILDtask running a powershell script. […]
Yep, we discovered as well. It looked nice and calm and no errors, just didn't work ;-)
#1197 has a patch that fixes this for good in our tests (cmake+msvc, cmake+mingw, autoconf+mingw). It might not be fully correct autoconf style yet, but it works ;-)
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1188?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I423c9880def0eb479abb72bef2e8034a73cf5905
Gerrit-Change-Number: 1188
Gerrit-PatchSet: 3
Gerrit-Owner: stipa <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-Reviewer: selvanair <[email protected]...>
Gerrit-CC: cron2 <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Comment-Date: Thu, 18 Sep 2025 17:20:01 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: cron2 <[email protected]...>
Comment-In-Reply-To: flichtenheld <[email protected]...>
Comment-In-Reply-To: selvanair <[email protected]...>
Comment-In-Reply-To: stipa <[email protected]...>
Gerrit-MessageType: comment